import java.rmi.server.UID;
import java.util.ArrayList;


public class functions extends initial{
	
	
	
	/*
	 * 	getBoardAndSet(int targetId)	:
	 * 			is used to get a board's information, including the list on it and card on list...
	 * 			so, a user interface can define their content here
	 */
	public void getBoardAndSet(int targetId){
		board object = newBoard.getBoard(targetId); // here to find the board
		
		ArrayList<aList> array01 = object.getAllList();
		for ( aList object2 : array01){	// for every list on the board
			
			/*
			 *  here you can do everything with list:object2
			 */
			
			ArrayList<card> array02 = object2.getAllCard();
			for ( card object3 : array02){	// for every card on the list
				
				/*
				 *  here you can do everything with card:object3
				 */
			}
			
			
		}
		ArrayList<member> array03 = object.getAllMember();
		for ( member object4 : array03){	// for every member on the board
			
			/*
			 *  here you can do everything with member:object4
			 */
			
		}
		ArrayList<label> array04 = object.getAllLabel();
		for ( label object5 : array04){	// for every member on the board
			
			/*
			 *  here you can do everything with label:object5
			 */
			
		}
	}	
	
	public board getBoardById(int targetId){
		ArrayList<board> array = newBoard.getALL();
		for (board doc : array){
			if ( doc.getId() == targetId){
				return doc;
			}
		}
		System.out.println("Can not find board by ID : "+targetId);
		return null;
	}
	
	public aList getListById(int targetId){
		
		for (aListInfor doc : newList){
			ArrayList<aList> array01 = doc.getAll();
			for (aList doc2 : array01){
				if (doc2.getId() == targetId){
					return doc2;
				}
			}
		}
		System.out.println("Can not find List by ID : "+targetId);
		return null;
	}
	
	public card getCardById(int targetId){
		for (cardInfor doc : newCard){
			for (card doc2 : doc.getAll()){
				if ( doc2.getId() == targetId ){
					return doc2;
				}
			}
		}
		System.out.println("Can not find board by ID : "+targetId);
		return null;
	}
	
	public member getMemberByBIdAndUId(int BId,int UId){
		ArrayList<board> array = newBoard.getALL();
		for (board doc : array){
			if ( doc.getId() == BId){
				ArrayList<member> array02 = doc.getAllMember();
				for ( member doc2 : array02){
					if (doc2.getID() == UId){
						return doc2;
					}
				}
			}
		}
		System.out.println("Can not find Member with ID : "+UId+" on boardId : "+BId);
		return null;
	}
	public label getLabelByLabelIdAndBId(int LabelId,int BId){
		ArrayList<board> array = newBoard.getALL();
		for (board doc : array){
			if ( doc.getId() == BId){
				ArrayList<label> array02 = doc.getAllLabel();
				for ( label doc2 : array02){
					if (doc2.getId() == LabelId){
						return doc2;
					}
				}
			}
		}
		System.out.println("Can not find Member with ID : "+LabelId+" on boardId : "+BId);
		return null;
	}
	
	public void initial(){
		ArrayList<Integer> BId_B = new ArrayList<Integer>();
		ArrayList<Integer> UId_B= new ArrayList<Integer>();
		ArrayList<String> BTitle= new ArrayList<String>();
		
		ArrayList<Integer> LId_L= new ArrayList<Integer>();
		ArrayList<Integer> BId_L= new ArrayList<Integer>();
		ArrayList<String> LTitle= new ArrayList<String>();
		ArrayList<Boolean> visible= new ArrayList<Boolean>();
		
		ArrayList<Integer> CId_C = new ArrayList<Integer>(); 
		ArrayList<Integer> UId_C = new ArrayList<Integer>();
		ArrayList<Integer> LId_C = new ArrayList<Integer>();
		ArrayList<String> dateStart_C = new ArrayList<String>();
		ArrayList<String> dateEnd_C = new ArrayList<String>();
		ArrayList<String> CTitle = new ArrayList<String>();
		ArrayList<String> content_C = new ArrayList<String>();
		ArrayList<Integer> LabelId_C = new ArrayList<Integer>();
		
		ArrayList<Integer> UId_M = new ArrayList<Integer>();
		ArrayList<Integer> BId_M = new ArrayList<Integer>();
		ArrayList<Boolean> isAdmin_M = new ArrayList<Boolean>();
		
		ArrayList<Integer> LabelId_Lb = new ArrayList<Integer>();
		ArrayList<Integer> BId_Lb = new ArrayList<Integer>();
		ArrayList<String> LabelName_Lb = new ArrayList<String>();
		
		// board
		BId_B.add(1);
		BId_B.add(2);
		BId_B.add(3);
		UId_B.add(100);
		UId_B.add(200);
		UId_B.add(300);
		BTitle.add("BoardA");
		BTitle.add("BoardB");
		BTitle.add("BoardC");
		
		// list
		BId_L.add(1);	BId_L.add(2);	BId_L.add(3);
		BId_L.add(1);	BId_L.add(2);	BId_L.add(3);
		BId_L.add(1);	BId_L.add(2);	BId_L.add(3);
		
		LId_L.add(1);	LId_L.add(2);	LId_L.add(3);
		LId_L.add(4);	LId_L.add(5);	LId_L.add(6);
		LId_L.add(7);	LId_L.add(8);	LId_L.add(9);
		
		LTitle.add("List1");	LTitle.add("List2");	LTitle.add("List3");	
		LTitle.add("List4");	LTitle.add("List5");	LTitle.add("List6");	
		LTitle.add("List7");	LTitle.add("List8");	LTitle.add("List9");
		
		visible.add(true);	visible.add(true);	visible.add(true);
		visible.add(true);	visible.add(true);	visible.add(true);
		visible.add(true);	visible.add(true);	visible.add(true);
		
		// card
		CId_C.add(1);	CId_C.add(2);	CId_C.add(3);
		CId_C.add(4);	CId_C.add(5);	CId_C.add(6);
		CId_C.add(7);	CId_C.add(8);	CId_C.add(9);
		
		UId_C.add(100);		UId_C.add(202);		UId_C.add(442);
		UId_C.add(644);		UId_C.add(130);		UId_C.add(11);
		UId_C.add(188);		UId_C.add(402);		UId_C.add(123);
		
		LId_C.add(9);	LId_C.add(6);	LId_C.add(1);
		LId_C.add(8);	LId_C.add(7);	LId_C.add(3);
		LId_C.add(2);	LId_C.add(5);	LId_C.add(4);
		
		dateStart_C.add("20120406");	dateStart_C.add("20100215");	dateStart_C.add("20070406");
		dateStart_C.add("20131208");	dateStart_C.add("20041026");	dateStart_C.add("20090606");
		dateStart_C.add("20150526");	dateStart_C.add("20050406");	dateStart_C.add("20120806");
		
		dateEnd_C.add("20150709");	dateEnd_C.add("20140709");	dateEnd_C.add("20130709");	
		dateEnd_C.add("20170709");	dateEnd_C.add("20080709");	dateEnd_C.add("20140709");
		dateEnd_C.add("20180709");	dateEnd_C.add("20140709");	dateEnd_C.add("20151120");
		
		CTitle.add("card1");	CTitle.add("card2");	CTitle.add("card3");
		CTitle.add("card6");	CTitle.add("card5");	CTitle.add("card4");
		CTitle.add("card7");	CTitle.add("card8");	CTitle.add("card9");
		
		content_C.add("WTF0004451");	content_C.add("WTF00665f1");	content_C.add("WTF00ess68");
		content_C.add("WTF0000831");	content_C.add("WTF000sgd1");	content_C.add("WTF000sh01");
		content_C.add("WTF000fh0h");	content_C.add("WTF0004f51");	content_C.add("WTF00eds01");
		
		LabelId_C.add(8);	LabelId_C.add(2);	LabelId_C.add(7);
		LabelId_C.add(9);	LabelId_C.add(6);	LabelId_C.add(2);
		LabelId_C.add(3);	LabelId_C.add(3);	LabelId_C.add(1);
		
		// member
		UId_M.add(1);	UId_M.add(2);	UId_M.add(3);	
		UId_M.add(4);	UId_M.add(5);	UId_M.add(6);
		
		BId_M.add(3);	BId_M.add(2);	BId_M.add(3);
		BId_M.add(2);	BId_M.add(1);	BId_M.add(2);
		
		isAdmin_M.add(true);	isAdmin_M.add(false);	isAdmin_M.add(true);
		isAdmin_M.add(true);	isAdmin_M.add(true);	isAdmin_M.add(false);
		
		// label
		LabelId_Lb.add(1);	LabelId_Lb.add(2);	LabelId_Lb.add(3);
		LabelId_Lb.add(4);	LabelId_Lb.add(5);	LabelId_Lb.add(6);
		LabelId_Lb.add(7);	LabelId_Lb.add(8);	LabelId_Lb.add(9);
		
		BId_Lb.add(1);	BId_Lb.add(3);	BId_Lb.add(2);
		BId_Lb.add(1);	BId_Lb.add(1);	BId_Lb.add(1);
		BId_Lb.add(1);	BId_Lb.add(3);	BId_Lb.add(2);
		
		LabelName_Lb.add("labelName01");	LabelName_Lb.add("labelName02");	LabelName_Lb.add("labelName03");
		LabelName_Lb.add("labelName04");	LabelName_Lb.add("labelName05");	LabelName_Lb.add("labelName06");
		LabelName_Lb.add("labelName07");	LabelName_Lb.add("labelName08");	LabelName_Lb.add("labelName09");
		
		super.initialBoard(BId_B, UId_B, BTitle);
		super.initialLabel(LabelId_Lb,LabelName_Lb,BId_Lb);
		super.initialList(LId_L, BId_L, LTitle, visible);
		super.initialCard(CId_C, UId_C, LId_C, dateStart_C, dateEnd_C, CTitle, content_C,LabelId_C);
		super.initialMember(UId_M,isAdmin_M,BId_M);
		
		
	}
	
	public void test(){
		ArrayList<board> all = newBoard.getALL();
		if (all != null){
			for (board doc : all){
				System.out.println("Board : "+doc.getTitle()+" have " + doc.getBumOfLabelOnTheBoard()+" labels on it, including :");
				if (doc.getAllLabel() != null){
					for (label doc5 : doc.getAllLabel()){
							System.out.println("\t\tlabel name = "+doc5.getName());
					}
				}
				System.out.println("\tAnd have " + doc.getNumOfMemberOnTheBoard()+" members on it, including :");
				if (doc.getAllMember() != null){
					for (member doc4 : doc.getAllMember()){
							System.out.println("\t\tuserId = "+doc4.getuserID());
					}
				}
				System.out.println("\tAnd have "+doc.getBumOfListOnTheBoard()+" lists on it, including :");
				if (doc.getAllList() != null){
					for (aList doc2 : doc.getAllList()){
						System.out.println("\t" + doc2.getTitle()+" have "+doc2.getNumOfCardOnTheList()+" cards on it, including :");
						if (doc2.getAllCard() != null){
							for (card doc3 : doc2.getAllCard()){
								System.out.println("\t\t" + doc3.getTitle() +" which is labeled by ");
								System.out.println("\t\t\t"+doc3.getLabel().labelName);
								
							}
						}
					}
				}
				
				
			}
		}			
	}
}
